package com.telit.firecommand.controller;

import com.telit.common.entity.DataReturn;
import com.telit.firecommand.dto.CommFireRiskLevelDto;
import com.telit.firecommand.service.CommFireRiskLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fire-risk-level")
@Api(tags = "火险等级管理", description = "/fire-risk-level")
public class CommFireRiskLevelController {

    @Autowired
    private CommFireRiskLevelService commFireRiskLevelService;

    @PostMapping(value = "/add", produces = "application/json;charset=UTF-8")
    @ApiOperation("添加火险等级数据")
    public DataReturn add(@RequestBody CommFireRiskLevelDto dto) {
        return commFireRiskLevelService.add(dto);
    }

    @GetMapping(value = "/listByPage", produces = "application/json;charset=UTF-8")
    @ApiOperation("分页条件查询火险等级信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "path", dataType = "int"),
            @ApiImplicitParam(name = "rows", value = "每页条数", paramType = "path", dataType = "int"),
            @ApiImplicitParam(name = "fireSeasonName", value = "防火季名称", paramType = "path", dataType = "string")
    })
    public DataReturn listByPage(@RequestParam(required = false, defaultValue = "1") Integer page,
                                 @RequestParam(required = false, defaultValue = "10") Integer rows,
                                 @RequestParam(required = false) String fireSeasonName) {
        return commFireRiskLevelService.selectByPage(page, rows, fireSeasonName);
    }

    @GetMapping("/queryByName")
    @ApiOperation("根据防火季名称查询火险等级详情")
    @ApiImplicitParam(name = "fireSeasonName", value = "防火季名称")
    public DataReturn queryByName(@RequestParam String fireSeasonName) {
        return commFireRiskLevelService.queryByName(fireSeasonName);
    }

    @PostMapping(value = "/updateByName", produces = "application/json;charset=UTF-8")
    @ApiOperation("编辑火险等级数据")
    public DataReturn updateByName(@RequestBody CommFireRiskLevelDto dto) {
        return commFireRiskLevelService.updateByName(dto);
    }

    @GetMapping("/deleteByName")
    @ApiOperation("根据防火季名称删除火险等级详情")
    @ApiImplicitParam(name = "fireSeasonName", value = "防火季名称")
    public DataReturn deleteByName(@RequestParam String fireSeasonName) {
        commFireRiskLevelService.deleteByName(fireSeasonName);
        return DataReturn.ok();
    }

    @GetMapping("/release")
    @ApiOperation("发布按钮功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fireSeasonName", value = "防火季名称"),
            @ApiImplicitParam(name = "isRelease", value = "是否发布")
    })
    public DataReturn release(@RequestParam String fireSeasonName,@RequestParam String isRelease) {
        commFireRiskLevelService.release(fireSeasonName, isRelease);
        return DataReturn.ok();
    }

    @GetMapping("/getFireWarning")
    @ApiOperation("火险预警数据")
    public DataReturn getFireWarning(@RequestParam(required = false) String districtCode) {
        return DataReturn.ok(commFireRiskLevelService.getFireWarning(districtCode));
    }

    @GetMapping("/getFireLevelNum")
    @ApiOperation("获取火险等级饼状图统计数据")
    public DataReturn getFireLevelNum(@RequestParam(required = false) String districtCode) {
        return DataReturn.ok(commFireRiskLevelService.getFireLevelNum(districtCode));
    }

}
